USE [AnotherSuccessfulProcedure]

IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[PlayerWeaponStatsSelectByPlayerIdLogIdList]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
BEGIN
	DROP PROCEDURE dbo.PlayerWeaponStatsSelectByPlayerIdLogIdList
END


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Neil Wilson
-- Create date: 09/03/08
-- Description:	Player Victims Select By PlayerId and LogIdList
-- =============================================
CREATE PROCEDURE PlayerWeaponStatsSelectByPlayerIdLogIdList

			@Attacker_playerId varchar(30),
			@WeaponId varchar(2),
			@LogId varchar(8000)
	
AS
BEGIN


DECLARE @WeaponName varchar(50),
		@Kills int,
		@Deaths int,
		@KillDeathRatio varchar(8)

DECLARE @SQL varchar(600)


DECLARE @ResultSet TABLE (resultCount int)

-- KILLS
SET @SQL = 'SELECT COUNT(KillId) FROM KILLS WHERE Attacker_PlayerId = ''' + @Attacker_playerId + '''
				AND Attacker_weaponId = ' + @WeaponId + '
				AND LogId IN (' + @LogId + ')'

DELETE FROM @ResultSet
INSERT INTO @ResultSet EXEC(@SQL)
SELECT @Kills = resultCount FROM @ResultSet

-- Deaths
SET @SQL = 'SELECT COUNT(KillId) FROM KILLS WHERE Victim_PlayerId = ''' + @Attacker_playerId + '''
				AND Attacker_weaponId = ' + @WeaponId + '
				AND LogId IN (' + @LogId + ')'

DELETE FROM @ResultSet
INSERT INTO @ResultSet EXEC(@SQL)
select @Deaths = resultCount FROM @ResultSet

SELECT @WeaponName = WeaponFullName from [Weapons] WHERE WeaponId = @WeaponId
SET @KillDeathRatio = ''


SELECT @WeaponName AS [Weapon], @Kills AS [Kills], @Deaths AS [Deaths], 
@KillDeathRatio AS [KillDeathRatio], @WeaponId as [WeaponId]

END
GO

--  PlayerWeaponStatsSelectByPlayerIdLogIdList 'STEAM_0:1:6788967',4, '1'